﻿using MongoDB.Driver;
using Publicuse.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Publicuse.Interface
{
    public interface IMongodbService
    {
        public void GetTableInstance<T>(string tbname, Action<IMongoCollection<T>> action, out string msg) where T : class, new();

        bool DeleteTable(string tbname, out string msg);
        bool ClearTable<T>(string oldname, string newname, out string msg);

        bool Add<T>(string tbname, T t, out string msg);

        Task<AsyncModel<T>> AddAsync<T>(string tbname, T t);

        bool InsertMany<T>(string tbname, List<T> t, out string msg);

        Task<AsyncModel<T>> InsertManyAsync<T>(string tbname, List<T> t);

        bool Update<T>(string tbname, T t, string id, out string msg);

        Task<AsyncModel<T>> UpdateAsync<T>(string tbname, T t, string id);

        bool UpdateManay<T>(string tbname, Dictionary<string, string> dic, FilterDefinition<T> filter, out string msg);

        Task<AsyncModel<T>> UpdateManayAsync<T>(string tbname, Dictionary<string, string> dic, FilterDefinition<T> filter);

        bool DeleteOne<T>(string tbname, string id, out string msg);

        Task<AsyncModel<T>> DeleteOneAsync<T>(string tbname, string id);

        bool DeleteMany<T>(string tbname, FilterDefinition<T> filter, out string msg);

        Task<AsyncModel<T>> DeleteManyAsync<T>(string tbname, FilterDefinition<T> filter);

        long Count<T>(string tbname, FilterDefinition<T> filter, out string msg);

        Task<AsyncModel<T>> CountAsync<T>(string tbname, FilterDefinition<T> filter);

        bool FindOne<T>(string tbname, string id, out string msg, string[] field = null);

        Task<AsyncModel<T>> FindOneAsync<T>(string tbname, string id, string[] field = null);

        bool GetList<T>(string tbname, out string msg, FilterDefinition<T> filter, out List<T> list, string[] field = null, SortDefinition<T> sort = null);

        Task<AsyncModel<T>> GetListAsync<T>(string tbname, FilterDefinition<T> filter, string[] field = null, SortDefinition<T> sort = null);

        bool GetListByPage<T>(string tbname, FilterDefinition<T> filter, int pageIndex, int pageSize, out long count, out List<T> list, out string msg, string[] field = null, SortDefinition<T> sort = null);

        Task<AsyncModel<T>> GetListByPageAsync<T>(string tbname, int pageIndex, int pageSize, FilterDefinition<T> filter, SortDefinition<T> sort = null, string[] field = null);
    }
}
